package com.leyou.cart.listener;

import com.leyou.cart.service.CartService;
import com.leyou.common.constants.MQConstants;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;


/**
 * 监听订单结果
 */
@Component
public class CartListener {
   @Autowired
   private CartService cartService;

    /**
     * 生成订单
     */
    @RabbitListener(
            bindings =@QueueBinding(
                    value = @Queue(name = MQConstants.Queue.ORDER_GENERATED_QUEUE),
                    exchange = @Exchange(name = MQConstants.Exchange.ORDER_GENERATED_NAME,type = ExchangeTypes.TOPIC),
                    key = MQConstants.RoutingKey.ORDER_GENERATED_KEY
            )
    )
    public void sendOrder(Map<String, Object> skuOrderMap){
        cartService.deleteCart(skuOrderMap);
    }
}
